package com.egg.ylt.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.Utils.CustomUtils;
import com.egg.ylt.Utils.StatusBarUtil;
import com.egg.ylt.Utils.StringUtil;
import com.egg.ylt.fragment.FRA_GrowUpCurve;
import com.egg.ylt.fragment.FRA_GrowUpRecord;
import com.egg.ylt.pojo.TabEntity;
import com.egg.ylt.presenter.impl.GrowRecordPresenterImpl;
import com.yonyou.framework.library.base.BaseActivity;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.log.Elog;
import com.yonyou.framework.library.common.utils.ToastUtil;
import com.yonyou.framework.library.widgets.tablayout.CommonTabLayout;
import com.yonyou.framework.library.widgets.tablayout.CustomTabEntity;
import com.yonyou.framework.library.widgets.tablayout.OnTabSelectListener;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lijiateng on 2019/1/19.
 *
 * 使用 bundle 带入 babyId 信息，key 值为 key_baby_id
 *
 */

public class ACT_GrowUpRecord extends BaseActivity {

    public static final String KEY_BABY_ID = "key_baby_id";
    @BindView(R.id.rl_include_title)
    RelativeLayout mRlayout;
    @BindView(R.id.include_iv_back)
    ImageView ivBack;
    @BindView(R.id.include_tv_title)
    TextView tvTitle;
    @BindView(R.id.include_tv_right)
    TextView tvRight;

    @BindView(R.id.tl_record)
    CommonTabLayout tlRecord;
    @BindView(R.id.fl_record)
    FrameLayout flRecord;

    private String[] mTitles = {"记录列表", "身高曲线", "体重曲线"};
    private ArrayList<Fragment> mRecordFragments = new ArrayList<>();
    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();

    private String babyId;

    @Override
    public void showBusinessError(ErrorBean error) {

    }

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        babyId = extras.getString(KEY_BABY_ID, "");
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_grow_up_record;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void initViewsAndEvents() {
        StatusBarUtil.setStatusBarColor(this, R.color.ylt_style_orange);
        StatusBarUtil.StatusBarLightMode(this);
        CustomUtils.setImmersiveStatusBar(this,mRlayout);
        tvTitle.setText("成长记录");
        tvRight.setText("添加");
        ivBack.setVisibility(View.VISIBLE);
        tvRight.setVisibility(View.VISIBLE);

        for (int i = 0; i < mTitles.length; i++) {
            mTabEntities.add(new TabEntity(mTitles[i]));
        }

        mRecordFragments.add(FRA_GrowUpRecord.newInstance(babyId));
        mRecordFragments.add(FRA_GrowUpCurve.newInstance(FRA_GrowUpCurve.CURVE_HEIGHT, babyId));
        mRecordFragments.add(FRA_GrowUpCurve.newInstance(FRA_GrowUpCurve.CURVE_WEIGHT, babyId));

        tlRecord.setTabData(mTabEntities, this, R.id.fl_record, mRecordFragments);

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @OnClick({R.id.include_iv_back, R.id.include_tv_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.include_iv_back:
                finish();
                break;
            case R.id.include_tv_right:
                // 跳转新增页面
                Bundle bundle = new Bundle();
                bundle.putString(ACT_AddGrowRecord.KEY_BABY_ID, StringUtil.get(babyId));
                readyGo(ACT_AddGrowRecord.class, bundle);
                break;
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        switch (tlRecord.getCurrentTab()) {
            case 0: // 记录列表，刷新
                FRA_GrowUpRecord fraGrowUp = (FRA_GrowUpRecord) mRecordFragments.get(0);
                fraGrowUp.onRefresh();
                break;
        }
    }
}
